<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<!-- 
		   1.什么是json 
		    JSON（JavaScript Object Notation, JS对象简谱）是一种轻量级的数据交换格式
		    采用完全独立于编程语言的文本格式来存储和表示数据
		    易于人阅读和编写，同时也易于机器解析和生成，并有效地提升网络传输效率
		  2.语法
		    key:value
			
			{"name":"zhangsan","age":20,"sex":"男"}
			
			[{"name":"zhangsan","age":20,"sex":"男"},{"name":"lisi","age":30,"sex":"女"}]
		  3.JSON
		    JSON.parse(json格式字符串)
			返回值:对象
			
			
			
		-->
		<script type="text/javascript">
			// joson格式的字符串
			var jsonStr =
				'[{"name":"zhangsan","age":20,"sex":"男","class":[{"name":"27期","num":48}]},{"name":"lisi","age":30,"sex":"女"}]';
			//-----------------------json字符串->对象---------------------------------------------------------------
			//把json格式的字符串转成对象(数组对象)
			var jsonArrayObj = JSON.parse(jsonStr);
			var obj = jsonArrayObj[0];
			// console.log(obj.name);
			// console.log(obj.class[0].name);
			//-----------------------对象->json字符串---------------------------------------------------------------
			var stu = {
				name: 'zhangsan',
				age: 20
			}

			var js = JSON.stringify(stu);
			console.log(js);//{"name":"zhangsan","age":20}
		</script>

	</body>
</html>
